package com.launcher;

import java.util.List;
import java.util.Random;

import com.launcher.decorator.Engine;
import com.launcher.decorator.Fairring;
import com.launcher.decorator.Stage;

public class RocketService
{
	private IRocketDAO dao;
	private static RocketService instance = new RocketService();
	
	private RocketService() 
	{
		dao = RocketHibernateDAO.getInstance();
	}
	
	public static RocketService getInstance()
	{
		return instance;
	}
	
	public PayLoad getRandomPayLoad()
	{
		List<PayLoad> payloads = getPayLoads();
		
		if (payloads.size() > 0)
		{
			Random r = new Random();
			return payloads.get(r.nextInt(payloads.size()));
		}
		else 
		{
			return null;
		}
	}

	public List<PayLoad> getPayLoads()
	{
		return dao.getPayLoads();
	}

	public Fairring getFairring(int height)
	{
		return dao.getFairring(height);
	}

	public List<Engine> getEngines()
	{
		return dao.getEngines();
	}

	public List<Engine> getEnginesHL()
	{
		return dao.getEnginesHL();
	}

	public List<Fairring> getFairrings()
	{
		return dao.getFairrings();
	}

	public List<Stage> getStages()
	{
		return dao.getStages();
	}

	public List<Launch> getLaunches()
	{
		return dao.getLaunches();
	}

	public void saveLaunch(Launch launch)
	{
		dao.saveLaunch(launch);
	}

	public void saveRocket(Rocket r)
	{
		dao.saveRocket(r);
	}

	public void savePayLoad(PayLoad payload)
	{
		dao.savePayLoad(payload);
	}
}
